import { _decorator, Component, LabelComponent, Node, Sprite, Color } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Tile')
export class Tile extends Component {

    @property(Sprite)
    public bg: Sprite = null;

    @property(LabelComponent)
    public text: LabelComponent = null;

    public num: number = 0;

    public init(num: number) {
        this.num = num;
        this.text.string = num.toString();
        this.setColor(num);
    }

    public getNum() {
        return this.num;
    }

    private setColor(num: number) {
        switch (num) {
            case Math.pow(2, 1):
                this.bg.color = Color.fromHEX(new Color(), "#eee4da");
                break;
            case Math.pow(2, 2):
                this.bg.color = Color.fromHEX(new Color(), "#ede0c8");
                break;
            case Math.pow(2, 3):
                this.bg.color = Color.fromHEX(new Color(), "#f2b179");
                break;
            case Math.pow(2, 4):
                this.bg.color = Color.fromHEX(new Color(), "#f59563");
                break;
            case Math.pow(2, 5):
                this.bg.color = Color.fromHEX(new Color(), "#f67c5f");
                break;
            case Math.pow(2, 6):
                this.bg.color = Color.fromHEX(new Color(), "#f65e3b");
                break;
            case Math.pow(2, 7):
                this.bg.color = Color.fromHEX(new Color(), "#edcf72");
                break;
            case Math.pow(2, 8):
                this.bg.color = Color.fromHEX(new Color(), "#edcc61");
                break;
            case Math.pow(2, 9):
                this.bg.color = Color.fromHEX(new Color(), "#edc850");
                break;
            case Math.pow(2, 10):
                this.bg.color = Color.fromHEX(new Color(), "#edc53f");
                break;
            case Math.pow(2, 11):
                this.bg.color = Color.fromHEX(new Color(), "#edc22e");
                break;
            case Math.pow(2, 12):
                this.bg.color = Color.fromHEX(new Color(), "#ecbc1c");
                break;
        }
    }
}


